<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            padding: 10px;
            border: 1px solid #333;
            /* overflow: hidden; */
            overflow-y: scroll;
        }

        .sub {
            width: 800px;
            height: 1000px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
    var box = document.getElementsByClassName("box")[0]
    box.onscroll = function () {
        console.log("滚动条的位置", box.scrollLeft, box.scrollTop)
    }

</script>

</html>